#include "adc.h"
#include "serialcom.h"
#include "rtc.h"
//最大采样电压
#define MAX_VOLTAGE 3.3
void adc_init(void) {
	rADCCON &= ~0x3fff;
	rADCCON |= 1 << 14;
	rADCCON |= 24<<6;
}

void adc_sample(void) {
	//等待采样结束
	while (rADCCON & 1) {};
	//启动采样
	rADCCON |= 1;
	//等待采样结束
	while (!(rADCCON &(1 << 15))) {};
	int samValue = rADCDAT0;
	samValue &= 0x3ff;
	float vol = MAX_VOLTAGE*(samValue+0.0) / (1024+0.0);
	Uart_Printf("AIN0 Voltage: %.3f\n",vol);
}
